#include "StdAfx.h"
#include <cassert>
#include "AdderObject.h"
#include "AdderBytecodeEngine.h"
#include "AdderBuiltinClassFunction.h"

BuiltinClassFunction::BuiltinClassFunction()
{
	// Our builtin was initalized incorrectly.
	assert(false);
}

BuiltinClassFunction::BuiltinClassFunction(AdderObject* this_object, BuiltinClassFunction0 func)
{
	this->func0 = func;
	this->this_object = this_object;
	this->argument_count = 0;
	this->isBuiltin = true;
}

BuiltinClassFunction::BuiltinClassFunction(AdderObject* this_object, BuiltinClassFunction1 func)
{
	this->func1 = func;
	this->this_object = this_object;
	this->argument_count = 1;
	this->isBuiltin = true;
}

BuiltinClassFunction::BuiltinClassFunction(AdderObject* this_object, BuiltinClassFunction2 func)
{
	this->func2 = func;
	this->this_object = this_object;
	this->argument_count = 2;
	this->isBuiltin = true;
}

BuiltinClassFunction::BuiltinClassFunction(AdderObject* this_object, BuiltinClassFunction3 func)
{
	this->func3 = func;
	this->this_object = this_object;
	this->argument_count = 3;
	this->isBuiltin = true;
}

BuiltinClassFunction::BuiltinClassFunction(AdderObject* this_object, BuiltinClassFunction4 func)
{
	this->func4 = func;
	this->this_object = this_object;
	this->argument_count = 4;
	this->isBuiltin = true;
}

BuiltinClassFunction::BuiltinClassFunction(AdderObject* this_object, BuiltinClassFunction5 func)
{
	this->func5 = func;
	this->this_object = this_object;
	this->argument_count = 5;
	this->isBuiltin = true;
}

AdderValue * BuiltinClassFunction::execute(AdderBytecodeEngine* engine)
{
	assert(this->argument_count == 0);
	return ((*this->this_object).*(this->func0))(engine);
}

AdderValue * BuiltinClassFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1)
{
	assert(this->argument_count == 1);
	return ((*this->this_object).*(this->func1))(engine, arg1);
}

AdderValue * BuiltinClassFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2)
{
	assert(this->argument_count == 2);
	return ((*this->this_object).*(this->func2))(engine, arg1, arg2);
}

AdderValue * BuiltinClassFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2, AdderValue* arg3)
{
	assert(this->argument_count == 3);
	return ((*this->this_object).*(this->func3))(engine, arg1, arg2, arg3);
}

AdderValue * BuiltinClassFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2, AdderValue* arg3, AdderValue* arg4)
{
	assert(this->argument_count == 4);
	return ((*this->this_object).*(this->func4))(engine, arg1, arg2, arg3, arg4);
}

AdderValue * BuiltinClassFunction::execute(AdderBytecodeEngine* engine, AdderValue* arg1, AdderValue* arg2, AdderValue* arg3, AdderValue* arg4, AdderValue* arg5)
{
	assert(this->argument_count == 5);
	return ((*this->this_object).*(this->func5))(engine, arg1, arg2, arg3, arg4, arg5);
}